﻿
package bsplib;

class Vec3i 
{
    public var x : Int;
    public var y : Int;
    public var z : Int;
    
    public function new( x : Int, y : Int, z : Int ) 
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    public inline function clone() : Vec3i {
        return new Vec3i(x, y, z);
    }
    
    public inline function copy( v : Vec3i ) : Vec3i {
        x = v.x;
        y = v.y;
        z = v.z;
        return this;
    }
    
    public function toString() : String {
        return "<Vec3i " + x + ", " + y + ", " + z + " >";
    }
    
    public inline function add( v : Vec3i ) : Vec3i {
        x += v.x;
        y += v.y;
        z += v.z;
        return this;
    }
    
    public inline function cAdd( v1 : Vec3i, v2 : Vec3i ) : Vec3i {
        x = v1.x + v2.x;
        y = v1.y + v2.y;
        z = v1.z + v2.z;
        return this;
    }
    
    public inline function sub( v : Vec3i ) : Vec3i {
        x -= v.x;
        y -= v.y;
        z -= v.z;
        return this;
    }
    
    public inline function cSub( v1 : Vec3i, v2 : Vec3i ) : Vec3i {
        x = v1.x - v2.x;
        y = v1.y - v2.y;
        z = v1.z - v2.z;
        return this;
    }
    
    public inline function dot( v : Vec3i ) : Int {
        return x * x + y * y + z * z;
    }
    
    public inline function lengthSqr() : Int {
        return x * x + y * y + z * z;
    }
    
    public inline function length() : Float {
        return Math.sqrt( lengthSqr() );
    }
    
    public inline function scale( s : Int ) : Vec3i {
        x *= s;
        y *= s;
        z *= z;
        return this;
    }
    
    public inline function cScale( v : Vec3i, s : Int ) : Vec3i {
        x = v.x * s;
        y = v.y * s;
        x = v.z * s;
        return this;
    }
    
    public inline function cross ( v : Vec3i ) : Vec3i {
        var tmp1 = y * v.z - z * v.y;
        var tmp2 = z * v.x - x * v.z;
        z = x * v.y - y * v.x;
        x = tmp1;
        y = tmp2;
        return this;
    }
    
    public inline function cCross( v1 : Vec3i, v2 : Vec3i  ) : Vec3i {
        x = v1.y * v2.z - v1.z * v2.y;
		y = v1.z * v2.x - v1.x * v2.z;
		z = v1.x * v2.y - v1.y * v2.x;
        return this;
    }
    
}